//
//  UIBarButtonItem+Extension.swift
//  ZHTQWeibo
//
//  Created by ZHTQ on 2018/9/15.
//  Copyright © 2018年 ZHTQ. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    ///便利构造函数，创建一个带自定义按钮的Item， 图片 监听对象 方法
    convenience init(imageName: String, target: Any, action: Selector){
        //创建按钮 设置 属性
        let button = UIButton(type: UIButtonType.custom)
        button.setImage(UIImage(named: imageName), for: UIControlState.normal)
        button.setImage(UIImage(named: imageName + "_highlighted"), for: UIControlState.highlighted)
        button.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        button.sizeToFit()
        //按钮赋值
        self.init(customView: button)
    }
}
